$(document)
		.ready(
				function() {				

			
					$("#login").click(function(e) {
						e.preventDefault();

						// submition
						$.ajax({
							url : '../auth/j_spring_security_check',
							type : "POST",
							data : $("#login-form").serialize(),
							success : function(data, status) {
								if (data.success) {
									// redirect
									location.href = data.targetUrl;
								} else {
									$('div.error').remove();
									$('#login-form').before(
											'<div class="error">Your login attempt was not successful<br /> Reason: '
													+ data.errorMessage
													+ '<br /> Please try again.</p></div>');									
								}
							},

							error : function(request, status, error) {
								$("div.error").remove();
								$('#login-form')
										.before(
												'<div class="error">Login attempt failed. Please try again.<br /><br /> Please try again.</p></div>');
							}

						});
			
					});

				});